
package at.fhj.ase.clientarch.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import at.fhj.ase.clientarch.common.component.IHardwareComponent;

/**
 * Represents the object that is transfered by {@link IHardwareComponent}.<br>
 * In generel this object is used for traffic between server and client.<br>
 * All the information should be transfered in one object.
 * 
 * @author cja, sfe | www.fh-joanneum.at | Client Architectures and Design
 */
public class TransferObject implements Serializable {
  private static final long serialVersionUID = 6750492191717215464L;

  private final List<HardwareData> dataList = new ArrayList<HardwareData>();

  private final double cpuValue;
  private final double ramValue;

  /**
   * Creating a new object using this constructor.<br>
   * Note that the values cannot be changed afterwards, you <strong>have</strong> to specify them with the constructor.
   * 
   * @param cpuValue the current cpu value
   * @param ramValue the current ram value
   */
  public TransferObject(double cpuValue, double ramValue) {
    super(); // if a class is once inbetween
    this.cpuValue = cpuValue;
    this.ramValue = ramValue;
  }

  /**
   * Use this constructor if you want to have no current values but a lot of {@link HardwareData} to transfer to client
   */
  public TransferObject() {
    this(-1, -1); // save invalid values
  }

  public void addHardwareData(HardwareData hwData) {
    dataList.add(hwData);
  }

  public double getCpuValue() {
    return cpuValue;
  }

  public double getRamValue() {
    return ramValue;
  }

  public List<HardwareData> getDataList() {
    return Collections.unmodifiableList(dataList);
  }

  @Override
  public String toString() {
    return "CPU value: " + cpuValue + ", RAM value: " + ramValue;
  }
}
